<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>签到中</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <!--semantic-ui-->
    <link th:href="@{/css/semantic.min.css}" rel="stylesheet">
    <script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <style>
        html,body,#container{
            height:100%;
            width: 100%;
        }
        .info{
            width:26rem;
        }
    </style>
<body>
<div id='container'></div>
<div class="info">
    <h4 id='status'></h4><hr>
    <p id='result'></p><hr>
</div>

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=dbb7639fba12116f7835ef8c5dc1ce63"></script>
<script type="text/javascript">
    var map = new AMap.Map('container', {
        resizeEnable: true
    });
    AMap.plugin('AMap.Geolocation', function() {
        var geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 30000,          //超过10秒后停止定位，默认：5s
            buttonPosition:'LB',    //定位按钮的停靠位置
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点
            GeoLocationFirst: true,  //设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位

        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition(function(status,result){
            if(status=='complete'){
                onComplete(result)
            }else{
                onError(result)
            }
        });
    });
    //解析定位结果
    function onComplete(data) {
        $('#mybutton').show();
        document.getElementById('status').innerHTML='定位成功'
        var str = [];
        str.push('定位结果：' + data.position);
        // alert(data.position);
        str.push('定位类别：' + data.location_type);
        if(data.accuracy){
            str.push('精度：' + data.accuracy + ' 米');
        }//如为IP精确定位结果则没有精度信息
        str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
        document.getElementById('result').innerHTML = str.join('<br>');

        document.getElementById('location').innerHTML =data.position;
        document.getElementById('location2').innerHTML ='成功获取您的经纬度';
        // $("#location").val("123");

    }
    //解析定位错误信息
    function onError(data) {
        document.getElementById('status').innerHTML='定位失败';
        document.getElementById('result').innerHTML = '失败原因排查信息:'+data.message;
            $('#mybutton').hide();
    }
    $(document).ready(function () {
        $('#mybutton').hide();
    })
</script>

<form th:action="@{/stu/map/confirmsubmit}" method="post">
    <div class="input-card" style='width:28rem;'>
        <label style='color:grey' id="location2" >获取定位信息中...</label>
        <div class="input-item">
            <textarea id='location'  type="text" name="location" readonly required></textarea>
        </div>
        <input type="hidden" name="tea_id" th:value="${tea_map.getUser_id()}">
        <input type="hidden" name="tea_name" th:value="${tea_map.getUsername()}">
        <input type="hidden" name="tea_map_id" th:value="${tea_map.getId()}">
        <input type="submit" class="btn" id="mybutton" value="提交"/>
    </div>
</form>

</body>
</html>